package com.jeeplus.test.jlnu.mailingInfo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.test.jlnu.admissionInfo.domain.entity.AdmissionInfo;
import com.jeeplus.test.jlnu.admissionInfo.domain.entity.AllInfo;
import com.jeeplus.test.jlnu.archivalInfo.domain.entity.ArchParmerter;
import com.jeeplus.test.jlnu.mailingInfo.domain.entity.MailingInfo;
import com.jeeplus.test.jlnu.mailingInfo.domain.vo.MailingInfoVo;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface MailingInfoMapper extends BaseMapper<MailingInfo> {

    @Select({
            "<script>",
            "SELECT ma.*,",
            "       ad.archival_num AS archivalNum,",
            "       ad.case_title AS caseTitle,",
            "       ad.file_title AS fileTitle,",
            "       ad.save_location AS saveLocation,",
            "       ad.page_location AS pageLocation,",
            "       ad.page_num AS pageNum,",
            "       ad.examinee_num AS examineeNum,",
            "       ad.admission_num AS admissionNum,",
            "       ad.student_id AS studentId,",
            "       ad.name AS name,",
            "       ad.gender AS gender,",
            "       ad.birthday AS birthday,",
            "       ad.political_outlook AS politicalOutlook,",
            "       ad.nation AS nation,",
            "       ad.id_card AS idCard,",
            "       ad.plan_nature AS planNature,",
            "       ad.admission_schools AS admissionSchools,",
            "       ad.admission_academy AS admissionAcademy,",
            "       ad.admission_major AS admissionMajor,",
            "       ad.admission_time AS admissionTime,",
            "       ad.gradation AS gradation,",
            "       ad.educational_system AS educationalSystem,",
            "       ad.learning_forms AS learningForms,",
            "       ad.examinee_sort AS examineeSort,",
            "       ad.batch AS batch,",
            "       ad.graduation_school AS graduationSchool,",
            "       ad.source_area AS sourceArea,",
            "       ad.area_name AS areaName,",
            "       ad.home_address AS homeAddress,",
            "       ad.postal_code AS postalCode,",
            "       ad.phone_num AS phoneNum,",
            "       ad.info_source AS infoSource,",
            "       ad.remarks AS remarks,",
            "       ad.ext1 AS ext1,",
            "       ad.ext2 AS ext2,",
            "       ad.ext3 AS ext3,",
            "       ad.ext4 AS ext4,",
            "       ad.ext5 AS ext5,",
            "       ad.ext6 AS ext6,",
            "       ad.ext7 AS ext7,",
            "       ad.ext8 AS ext8,",
            "       ad.ext9 AS ext9,",
            "       ad.ext10 AS ext10,",
            "       ad.ext11 AS ext11,",
            "       ad.ext12 AS ext12,",
            "       ad.ext13 AS ext13,",
            "       ad.ext14 AS ext14,",
            "       ad.ext15 AS ext15,",
            "       ad.ext16 AS ext16,",
            "       ad.ext17 AS ext17,",
            "       ad.ext18 AS ext18,",
            "       ad.ext19 AS ext19,",
            "       ad.ext20 AS ext20",
            "FROM jlnu_mailing_info ma",
            "LEFT JOIN jlnu_admission_info ad ON ma.student_id = ad.student_id",
            "WHERE 1=1",
            "<if test='mailingInfoReqVo.name != null and mailingInfoReqVo.name != \"\"'>",
            "AND ad.name = #{mailingInfoReqVo.name}",
            "</if>",
            "<if test='mailingInfoReqVo.studentId != null and mailingInfoReqVo.studentId != \"\"'>",
            "AND ad.student_id = #{mailingInfoReqVo.studentId}",
            "</if>",
            "<if test='mailingInfoReqVo.admissionAcademy != null and mailingInfoReqVo.admissionAcademy != \"\"'>",
            "AND ad.admission_academy = #{mailingInfoReqVo.admissionAcademy}",
            "</if>",
            "<if test='mailingInfoReqVo.admissionMajor != null and mailingInfoReqVo.admissionMajor != \"\"'>",
            "AND ad.admission_major = #{mailingInfoReqVo.admissionMajor}",
            "</if>",
            "<if test='mailingInfoReqVo.phoneNum != null and mailingInfoReqVo.phoneNum != \"\"'>",
            "AND ad.phone_num = #{mailingInfoReqVo.phoneNum}",
            "</if>",
            "</script>"
    })
    Page<MailingInfo> getMailingInfoPage(ArchParmerter mailingInfoReqVo, Page<MailingInfo> page);
    @Update({
            "<script>",
            "UPDATE jlnu_mailing_info",
            "<set>",
            "<if test='mailingInfo.grade != null and mailingInfo.grade != \"\"'> grade = #{mailingInfo.grade}, </if>",
            "<if test='mailingInfo.classId != null'> class_id = #{mailingInfo.classId}, </if>",
            "<if test='mailingInfo.age != null'> age = #{mailingInfo.age}, </if>",
            "<if test='mailingInfo.schoolCode != null and mailingInfo.schoolCode != \"\"'> school_code = #{mailingInfo.schoolCode}, </if>",
            "<if test='mailingInfo.graduationCollege != null and mailingInfo.graduationCollege != \"\"'> graduation_college = #{mailingInfo.graduationCollege}, </if>",
            "<if test='mailingInfo.majorCode != null'> major_code = #{mailingInfo.majorCode}, </if>",
            "<if test='mailingInfo.qualification != null'> qualification = #{mailingInfo.qualification}, </if>",
            "<if test='mailingInfo.entranceDate != null'> entrance_date = #{mailingInfo.entranceDate}, </if>",
            "<if test='mailingInfo.graduationDate != null'> graduation_date = #{mailingInfo.graduationDate}, </if>",
            "<if test='mailingInfo.completionConclusion != null and mailingInfo.completionConclusion != \"\"'> completion_conclusion = #{mailingInfo.completionConclusion}, </if>",
            "<if test='mailingInfo.graduationDestination != null and mailingInfo.graduationDestination != \"\"'> graduation_destination = #{mailingInfo.graduationDestination}, </if>",
            "<if test='mailingInfo.employmentName != null and mailingInfo.employmentName != \"\"'> employment_name = #{mailingInfo.employmentName}, </if>",
            "<if test='mailingInfo.employmentAddress != null and mailingInfo.employmentAddress != \"\"'> employment_address = #{mailingInfo.employmentAddress}, </if>",
            "<if test='mailingInfo.archiveTransferNum != null'> archive_transfer_num = #{mailingInfo.archiveTransferNum}, </if>",
            "<if test='mailingInfo.archiveTransferSort != null'> archive_transfer_sort = #{mailingInfo.archiveTransferSort}, </if>",
            "<if test='mailingInfo.receivePostalCode != null and mailingInfo.receivePostalCode != \"\"'> receive_postal_code = #{mailingInfo.receivePostalCode}, </if>",
            "<if test='mailingInfo.receiveUnitName != null and mailingInfo.receiveUnitName != \"\"'> receive_unit_name = #{mailingInfo.receiveUnitName}, </if>",
            "<if test='mailingInfo.receiveUnitAddress != null and mailingInfo.receiveUnitAddress != \"\"'> receive_unit_address = #{mailingInfo.receiveUnitAddress}, </if>",
            "<if test='mailingInfo.receiveUnitAddressCode != null and mailingInfo.receiveUnitAddressCode != \"\"'> receive_unit_address_code = #{mailingInfo.receiveUnitAddressCode}, </if>",
            "<if test='mailingInfo.archiveReceiver != null and mailingInfo.archiveReceiver != \"\"'> archive_receiver = #{mailingInfo.archiveReceiver}, </if>",
            "<if test='mailingInfo.archiveReceiverPhone != null and mailingInfo.archiveReceiverPhone != \"\"'> archive_receiver_phone = #{mailingInfo.archiveReceiverPhone}, </if>",
            "<if test='mailingInfo.sender != null and mailingInfo.sender != \"\"'> sender = #{mailingInfo.sender}, </if>",
            "<if test='mailingInfo.sendTime != null'> send_time = #{mailingInfo.sendTime}, </if>",
            "<if test='mailingInfo.shipMethod != null and mailingInfo.shipMethod != \"\"'> ship_method = #{mailingInfo.shipMethod}, </if>",
            "<if test='mailingInfo.trackingNumber != null and mailingInfo.trackingNumber != \"\"'> tracking_number = #{mailingInfo.trackingNumber}, </if>",
            "<if test='mailingInfo.receipt != null'> receipt = #{mailingInfo.receipt}, </if>",
            "<if test='mailingInfo.studentPhoneNum != null and mailingInfo.studentPhoneNum != \"\"'> student_phone_num = #{mailingInfo.studentPhoneNum}, </if>",
            "<if test='mailingInfo.responsiblePerson != null and mailingInfo.responsiblePerson != \"\"'> responsible_person = #{mailingInfo.responsiblePerson}, </if>",
            "<if test='mailingInfo.dateTime != null'> date_time = #{mailingInfo.dateTime}, </if>",
            "<if test='mailingInfo.standards != null'> standards = #{mailingInfo.standards}, </if>",
            "<if test='mailingInfo.quantity != null'> quantity = #{mailingInfo.quantity}, </if>",
            "<if test='mailingInfo.pageCount != null'> page_count = #{mailingInfo.pageCount}, </if>",
            "<if test='mailingInfo.archiveUnit != null and mailingInfo.archiveUnit != \"\"'> archive_unit = #{mailingInfo.archiveUnit}, </if>",
            "<if test='mailingInfo.transferor != null and mailingInfo.transferor != \"\"'> transferor = #{mailingInfo.transferor}, </if>",
            "<if test='mailingInfo.receiver != null and mailingInfo.receiver != \"\"'> receiver = #{mailingInfo.receiver}, </if>",
            "<if test='mailingInfo.approvalStatus != null and mailingInfo.approvalStatus != \"\"'> approval_status = #{mailingInfo.approvalStatus},</if>",
            "<if test='mailingInfo.modifyApprovalStatus != null and mailingInfo.modifyApprovalStatus != \"\"'> modify_approval_status = #{mailingInfo.modifyApprovalStatus},</if>",
            "<if test='mailingInfo.rejectionReason != null and mailingInfo.rejectionReason != \"\"'> rejection_reason = #{mailingInfo.rejectionReason},</if>",
            "<if test='mailingInfo.rejectionReasonItem != null and mailingInfo.rejectionReasonItem != \"\"'> rejection_reason_item = #{mailingInfo.rejectionReasonItem},</if>",
            "<if test='mailingInfo.modificationOpinions != null and mailingInfo.modificationOpinions != \"\"'> modification_opinions = #{mailingInfo.modificationOpinions},</if>",
            "<if test='mailingInfo.modificationTime != null and mailingInfo.modificationTime != \"\"'> modification_time = #{mailingInfo.modificationTime},</if>",
            "<if test='mailingInfo.minioId != null and mailingInfo.minioId != \"\"'> minio_id = #{mailingInfo.minioId},</if>",
            "</set>",
            "WHERE student_id = #{mailingInfo.studentId}",
            "</script>"
    })
    int updateByStuid(@Param("mailingInfo") MailingInfo mailingInfo);

    @Insert("INSERT INTO jlnu_mailing_info (" +
            "student_id, grade, class_id, age, school_code, graduation_college, major_code, qualification, entrance_date, graduation_date, " +
            "completion_conclusion, graduation_destination, employment_name, employment_address, archive_transfer_num, archive_transfer_sort, " +
            "receive_postal_code, receive_unit_name, receive_unit_address, receive_unit_address_code, archive_receiver, archive_receiver_phone, " +
            "sender, send_time, ship_method, tracking_number, receipt, student_phone_num, responsible_person, date_time, standards, " +
            "quantity, page_count, archive_unit, transferor, receiver, transfer_time, approval_status, modify_approval_status, rejection_reason, rejection_reason_item, modification_opinions, modification_time, minio_id) " +
            "VALUES (" +
            "#{studentId}, #{grade}, #{classId}, #{age}, #{schoolCode}, #{graduationCollege}, #{majorCode}, #{qualification}, " +
            "#{entranceDate}, #{graduationDate}, #{completionConclusion}, #{graduationDestination}, #{employmentName}, #{employmentAddress}, " +
            "#{archiveTransferNum}, #{archiveTransferSort}, #{receivePostalCode}, #{receiveUnitName}, #{receiveUnitAddress}, " +
            "#{receiveUnitAddressCode}, #{archiveReceiver}, #{archiveReceiverPhone}, #{sender}, #{sendTime}, #{shipMethod}, " +
            "#{trackingNumber}, #{receipt}, #{studentPhoneNum}, #{responsiblePerson}, #{dateTime}, #{standards}, #{quantity}, " +
            "#{pageCount}, #{archiveUnit}, #{transferor}, #{receiver}, #{transferTime}, #{approvalStatus}, #{modifyApprovalStatus}, #{rejectionReason}, #{rejectionReasonItem}, #{modificationOpinions}, #{modificationTime}, #{minioId})")
    int saveMail(MailingInfo mailingInfo);

    @Select("select count(*) from jlnu_admission_info where student_id = #{studentId}")
    int checkStudentId(String studentId);
@Insert("insert into jlnu_admission_info (admission_time,archival_num,case_title,file_title,save_location,page_location,page_num,admission_major,educational_system,learning_forms,gradation,source_area,remarks,student_id,admission_num,admission_academy,examinee_num,name,gender,birthday,political_outlook,nation,id_card,graduation_school) values(" +
        "#{admissionTime},#{archivalNum},#{caseTitle},#{fileTitle},#{saveLocation},#{pageLocation},#{pageNum},#{admissionMajor},#{educationalSystem},#{learningForms},#{gradation},#{sourceArea},#{remarks},#{studentId},#{admissionNum},#{admissionAcademy},#{examineeNum},#{name},#{gender},#{birthday},#{politicalOutlook},#{nation},#{idCard},#{graduationSchool})")
    void saveAdmission(MailingInfo mailingInfo);

    void insertDataMailingInfo(@Param("mailingInfoVo") List<MailingInfoVo> dataList);

    MailingInfoVo selectMailingById(@Param("id") Long id);

    Page<MailingInfo> selectAllMailingVOs(@Param("mailingInfoVo")MailingInfoVo mailingInfoVo, Page<MailingInfo> page);

    List<MailingInfo> selectBatchIds(@Param("ids") List<String> ids);

    int batchUpdateMailing(@Param("admissionInfos") List<MailingInfoVo> admissionInfos,@Param("transferState") String transferState);

}
